package org.test.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.test.model.User;
import org.test.netty.UserGroup;
import org.test.service.IUserService;
import org.test.utils.Md5Util;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	IUserService userService;
	
	@RequestMapping(value="/get",method=RequestMethod.GET)
	@ResponseBody
	public User getUser(User user) {
		return userService.findUser(user);
	}
	
	@RequestMapping(value="/index",method=RequestMethod.POST)
	public String showChatPage(String userName,String userPwd,Model model) {
		User loginUser = userService.findUserByAccountAndPwd(userName, Md5Util.getMD5(userPwd));
		if(loginUser != null) {
			
			model.addAttribute("userId",loginUser.getUserId());
			model.addAttribute("allUsers",userService.findUserList());
		}else {
			model.addAttribute("errorMsg","用户名或者密码错误！");
			return "error";
		}
		return "index";
	}
	
	
	
}
